package vuelos;


import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.WindowConstants;

@SuppressWarnings("serial")
public class ClientScreen extends javax.swing.JInternalFrame {
	
	private int Ancho = 760;
	private int Alto  = 560;
	
	private Thread Quitando;
	private Thread Trayendo;
	
	private String UsuarioActual;
	
	private MainWindow FatherWindow;
	
	private JNovaButton BotonOcultar;

	// Constructor
	public ClientScreen (MainWindow fatherWindow) {
		super();
		FatherWindow = fatherWindow;
		Quitando = null;
		Trayendo = null;
		
		initComponents();
	}
	
	// Init Components
	public void initComponents() {
        this.setBounds(-1000, 20, Ancho, Alto);
        this.setTitle("Acceso Cliente");
        getContentPane().setLayout(null);
        this.setClosable(false);
        this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        this.setMaximizable(false);
        this.setVisible(true);        
        
        // Boton Ocultar
        BotonOcultar = new JNovaButton("/images/BotonOcultarFree.png", "/images/BotonOcultarArmed.png");        
        getContentPane().add(BotonOcultar);
        BotonOcultar.setBounds(686, 466, BotonOcultar.getPreferredSize().width, BotonOcultar.getPreferredSize().height);
        BotonOcultar.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent evt) {
				BotonOcultarMouseClicked(evt);
			}
		});
        BotonOcultar.repaint();        

	}
	
	@SuppressWarnings("deprecation")
	public void traer(String usuarioActual){
		if(Quitando != null) {
			if(Quitando.isAlive()) {
			   Quitando.stop();
		}}
		Trayendo = new Thread(new ClientScreenTraer (this));
		Trayendo.start();
		
		UsuarioActual = usuarioActual;
		this.setTitle(this.getTitle() + ": " + UsuarioActual);
	}
	
	@SuppressWarnings("deprecation")
	private void quitar() {
		if(Trayendo != null) {
		    if (Trayendo.isAlive()) {
		 	    Trayendo.stop();
		}}
		Quitando = new Thread(new ClientScreenQuitar (this));
		Quitando.start();
		
		UsuarioActual = "";
	}	
	
	private void BotonOcultarMouseClicked(MouseEvent evt) {
		new PlaySound("/sounds/ButtonClick.wav").start();
		this.quitar();
		FatherWindow.showLoginWindow();
	}
	
}
